<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>使用 Create-React-App 开发 Chrome 扩展 - 早起的年轻人</title>
    <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="早起的年轻人" /><meta name="description" content=" 整理 Kindle 标注、书签和笔记从未如此简单！
 Kindle 标注管理应用 Kindle Mate 只支持 Windows，不支持 Mac。标注只是解析我的剪贴文本文件，配合 FileReader API，写个 Chrome 扩展解析文本文件就好了。
" /><meta name="keywords" content="管理, Github, Vue, flutter, Go" />






<meta name="generator" content="Hugo 0.79.1 with even 4.0.0" />


<link rel="canonical" href="https://luckly.work/post/2019/2019-07-07-create-react-app-chrome-extension/" />
<link href="/post/2019/2019-07-07-create-react-app-chrome-extension/" rel="alternate" type="application/rss+xml" title="早起的年轻人" />
<link href="/post/2019/2019-07-07-create-react-app-chrome-extension/" rel="feed" type="application/rss+xml" title="早起的年轻人" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<link href="/dist/even.06658218.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">
<link rel="stylesheet" href="/css/reset-even.css">


<meta property="og:title" content="使用 Create-React-App 开发 Chrome 扩展" />
<meta property="og:description" content="
整理 Kindle 标注、书签和笔记从未如此简单！

Kindle 标注管理应用 Kindle Mate 只支持 Windows，不支持 Mac。标注只是解析我的剪贴文本文件，配合 FileReader API，写个 Chrome 扩展解析文本文件就好了。" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://luckly.work/post/2019/2019-07-07-create-react-app-chrome-extension/" />
<meta property="article:published_time" content="2019-07-07T22:28:34+08:00" />
<meta property="article:modified_time" content="2019-07-07T22:28:34+08:00" />
<meta itemprop="name" content="使用 Create-React-App 开发 Chrome 扩展">
<meta itemprop="description" content="
整理 Kindle 标注、书签和笔记从未如此简单！

Kindle 标注管理应用 Kindle Mate 只支持 Windows，不支持 Mac。标注只是解析我的剪贴文本文件，配合 FileReader API，写个 Chrome 扩展解析文本文件就好了。">
<meta itemprop="datePublished" content="2019-07-07T22:28:34+08:00" />
<meta itemprop="dateModified" content="2019-07-07T22:28:34+08:00" />
<meta itemprop="wordCount" content="1318">



<meta itemprop="keywords" content="“React”,Chrome," />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="使用 Create-React-App 开发 Chrome 扩展"/>
<meta name="twitter:description" content="
整理 Kindle 标注、书签和笔记从未如此简单！

Kindle 标注管理应用 Kindle Mate 只支持 Windows，不支持 Mac。标注只是解析我的剪贴文本文件，配合 FileReader API，写个 Chrome 扩展解析文本文件就好了。"/>

</head>
<body>
<div id="mobile-navbar" class="mobile-navbar">
    <div class="mobile-header-logo">
        <a href="/" class="logo">早起的年轻人</a>
    </div>
    <div class="mobile-navbar-icon">
        <span></span>
        <span></span>
        <span></span>
    </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
    <ul class="mobile-menu-list">
        <a href="/">
            <li class="mobile-menu-item" title="首页">首页</li>
        </a>
        <a href="/post/">
            <li class="mobile-menu-item" title="归档">归档</li>
        </a>
        <a href="/categories/">
            <li class="mobile-menu-item" title="分类">分类</li>
        </a>
        <a href="/tags/">
            <li class="mobile-menu-item" title="标签">标签</li>
        </a>
        <a href="/about/">
            <li class="mobile-menu-item" title="关于我">关于我</li>
        </a>
        <a href="/friend/">
            <li class="mobile-menu-item" title="友链">友链</li>
        </a>
        <a href="https://github.com/ITmxs/">
            <li class="mobile-menu-item" title="阅读清单">阅读清单</li>
        </a>
        
    </ul>
    <form class="search-form" style="position: absolute;">
    <input name="search" type="search" style="height: 28px;padding-left: 30px;"/>
    <input type="image" src="/img/search.svg" alt="Search" style="position: absolute;left: 6px;top: 6px;"/>
</form>


</nav>

<div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/%20/" class="logo">早起的年轻人</a>
</div>

<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
      <a class="menu-item-link" href="/">首页</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/post/">归档</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/categories/">分类</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/tags/">标签</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/about/">关于我</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="/friend/">友链</a>
    </li><li class="menu-item">
      <a class="menu-item-link" href="https://github.com/ITmxs/">阅读清单</a>
    </li>
  </ul>
</nav>
        <form class="search-form" style="position: absolute;">
    <input name="search" type="search" style="height: 28px;padding-left: 30px;"/>
    <input type="image" src="/img/search.svg" alt="Search" style="position: absolute;left: 6px;top: 6px;"/>
</form>



    </header>


    <main id="main" class="main">
        <div class="content-wrapper">
            <div id="content" class="content">
                <article class="post">
  
  <header class="post-header">
    <h1 class="post-title">使用 Create-React-App 开发 Chrome 扩展</h1>

    <div class="post-meta">
      <span class="post-time"> 2019-07-07 22:28 </span>
      <div class="post-category">
        <a href="/categories/%E6%8A%80%E6%9C%AF/"> “技术” </a>
        </div>
      <span class="more-meta"> 约 1318 字 </span>
      <span class="more-meta"> 预计阅读 3 分钟 </span>
      <span id="busuanzi_container_page_pv" class="more-meta"> <span id="busuanzi_value_page_pv"><img src="/img/spinner.svg" alt="spinner.svg"/></span> 次阅读 </span>
    </div>
  </header>

  <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content">
    <nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#初始化项目">初始化项目</a></li>
        <li><a href="#支持-sass">支持 Sass</a></li>
        <li><a href="#读取文件">读取文件</a></li>
        <li><a href="#解析文本">解析文本</a></li>
        <li><a href="#配置-manifestjson">配置 manifest.json</a></li>
        <li><a href="#上传到-chrome-网上应用商店">上传到 Chrome 网上应用商店</a></li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</div>
  <div class="post-outdated">
    <div class="hint">
      <p>【注意】最后更新于 <span class="timeago" datetime="2019-07-07T22:28:34" title="July 7, 2019">July 7, 2019</span>，文中内容可能已过时，请谨慎使用。</p>
    </div>
  </div>
  <div class="post-content">
    <blockquote>
<p>整理 Kindle 标注、书签和笔记从未如此简单！</p>
</blockquote>
<p>Kindle 标注管理应用 <a href="https://kmate.me/cn/">Kindle Mate</a> 只支持 Windows，不支持 Mac。标注只是解析<strong>我的剪贴</strong>文本文件，配合 <a href="https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader">FileReader</a> API，写个 Chrome 扩展解析文本文件就好了。</p>
<ul>
<li>
<p><a href="https://chrome.google.com/webstore/detail/my-clippings/pcfdnhenjhhcbfbanepfegljllniecpe">Chrome 下载地址</a></p>
</li>
<li>
<p><a href="https://github.com/nusr/my-clippings">Github 地址</a></p>
</li>
</ul>
<h2 id="初始化项目">初始化项目</h2>
<p>安装 React 脚手架 create-react-app</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">npm i -g create-react-app
</code></pre></td></tr></table>
</div>
</div><p>初始化项目</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">create-react-app my-clippings --typescript
</code></pre></td></tr></table>
</div>
</div><p><strong>&ndash;typescript</strong> 表示使用 typescript。强烈推荐使用 ts，Vue 3.x 使用 ts 重写，Angular 2.x+ 只能使用 ts，ts 是大势所趋。</p>
<p>删除 <strong>src/serviceWorker.ts</strong> 文件，用不着。</p>
<h2 id="支持-sass">支持 Sass</h2>
<p>安装 node-sass 即可。
若要支持 css modules，文件名从 <strong>index.scss</strong> 改为 <strong>index.module.scss</strong> 即可。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-bash" data-lang="bash">npm i -D node-sass
</code></pre></td></tr></table>
</div>
</div><h2 id="读取文件">读取文件</h2>
<p>读取的文件是 Kindle 中的 <strong>/documents/My Clippings.txt</strong> 文件，Kindle 设置任何语言都是这个文件。只不过在不同语言下的显示不一样。
使用 <a href="https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader">FileReader</a> API 可以轻松读取文本文件。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-html" data-lang="html"><span class="cp">&lt;!DOCTYPE html&gt;</span>
<span class="p">&lt;</span><span class="nt">html</span> <span class="na">lang</span><span class="o">=</span><span class="s">&#34;en&#34;</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">meta</span> <span class="na">charset</span><span class="o">=</span><span class="s">&#34;UTF-8&#34;</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">title</span><span class="p">&gt;</span>Document<span class="p">&lt;/</span><span class="nt">title</span><span class="p">&gt;</span>
  <span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>

  <span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&#34;file&#34;</span> <span class="na">accept</span><span class="o">=</span><span class="s">&#34;.txt&#34;</span> <span class="na">id</span><span class="o">=</span><span class="s">&#34;file-upload&#34;</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">script</span><span class="p">&gt;</span>
      <span class="kr">const</span> <span class="nx">dom</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelector</span><span class="p">(</span><span class="s2">&#34;#file-upload&#34;</span><span class="p">);</span>
      <span class="nx">dom</span><span class="p">.</span><span class="nx">onchange</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span>
        <span class="kr">const</span> <span class="nx">file</span> <span class="o">=</span> <span class="nx">event</span><span class="p">.</span><span class="nx">currentTarget</span><span class="p">.</span><span class="nx">files</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
        <span class="kr">const</span> <span class="nx">reader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileReader</span><span class="p">();</span>
        <span class="nx">reader</span><span class="p">.</span><span class="nx">readAsText</span><span class="p">(</span><span class="nx">file</span><span class="p">);</span>

        <span class="nx">reader</span><span class="p">.</span><span class="nx">onload</span> <span class="o">=</span> <span class="p">()</span> <span class="p">=&gt;</span> <span class="p">{</span>
          <span class="kr">const</span> <span class="nx">temp</span> <span class="o">=</span> <span class="nx">reader</span><span class="p">.</span><span class="nx">result</span><span class="p">;</span>
          <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">temp</span><span class="p">);</span>
        <span class="p">};</span>
      <span class="p">};</span>
    <span class="p">&lt;/</span><span class="nt">script</span><span class="p">&gt;</span>
  <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="解析文本">解析文本</h2>
<p>要解析的文本为下面的格式，使用简单的正则表达式即可解析。
<strong>根据 Kindle 设置的语言，中文与英文的格式会稍有不同，需要做不同的解析。</strong></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-txt" data-lang="txt">==========
娱乐至死 (尼尔·波兹曼)
- 您在位置 #1882-1884的标注 | 添加于 2019年6月2日星期日 上午10:07:30

古希腊哲学家在2500年以前就说过，人常常以自己的形象塑造上帝。现在，电视政治又添了新招：那些想当上帝的人把自己塑造成观众期望的形象。
==========
娱乐至死 (尼尔·波兹曼)
- 您在位置 #1925-1927的标注 | 添加于 2019年6月2日星期日 上午10:11:09

历史的消失根本不需要如此残酷的手段，表面温和的现代技术通过为民众提供一种政治形象、瞬间快乐和安慰疗法，能够同样有效地让历史销声匿迹，也许还更恒久，并且不会遭到任何反对。
==========
娱乐至死 (尼尔·波兹曼)
- 您在位置 #1961-1963的标注 | 添加于 2019年6月2日星期日 上午10:14:42

自由不是靠关掉电视实现的。电视对于大多数人来说，是生活中最有吸引力的东西。我们生活在一个绝大多数人不会关掉电视的世界里。如果我们不直接从电视得到某种信息，我们也会通过其他人得到它。
==========
</code></pre></td></tr></table>
</div>
</div><h2 id="配置-manifestjson">配置 manifest.json</h2>
<p>发布 Chrome 应用需要配置 manifest.json 。
更多设置可以查看<a href="https://developer.chrome.com/extensions/manifest">开发文档</a></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-json" data-lang="json"><span class="p">{</span>
  <span class="nt">&#34;name&#34;</span><span class="p">:</span> <span class="s2">&#34;My Clippings&#34;</span><span class="p">,</span> <span class="err">//</span> <span class="err">扩展名</span>
  <span class="nt">&#34;short_name&#34;</span><span class="p">:</span> <span class="s2">&#34;Clippings&#34;</span><span class="p">,</span>
  <span class="nt">&#34;description&#34;</span><span class="p">:</span> <span class="s2">&#34;Organizing your Kindle Highlight、Bookmark and Notes so easy.&#34;</span><span class="p">,</span> <span class="err">//</span> <span class="err">描述</span>
  <span class="nt">&#34;version&#34;</span><span class="p">:</span> <span class="s2">&#34;0.0.6&#34;</span><span class="p">,</span> <span class="err">//</span> <span class="err">版本号，每次提交到</span> <span class="err">chrome</span> <span class="err">应用中心</span>
  <span class="nt">&#34;version_name&#34;</span><span class="p">:</span> <span class="s2">&#34;0.0.6&#34;</span><span class="p">,</span>
  <span class="nt">&#34;manifest_version&#34;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
  <span class="nt">&#34;author&#34;</span><span class="p">:</span> <span class="s2">&#34;Steve Xu&#34;</span><span class="p">,</span>
  <span class="nt">&#34;browser_action&#34;</span><span class="p">:</span> <span class="p">{</span>
    <span class="err">//</span> <span class="err">点击应用图标的操作</span>
    <span class="nt">&#34;default_icon&#34;</span><span class="p">:</span> <span class="s2">&#34;icon-48.png&#34;</span><span class="p">,</span>
    <span class="nt">&#34;default_title&#34;</span><span class="p">:</span> <span class="s2">&#34;My Clippings&#34;</span>
  <span class="p">},</span>
  <span class="nt">&#34;homepage_url&#34;</span><span class="p">:</span> <span class="s2">&#34;https://github.com/nusr/my-clippings&#34;</span><span class="p">,</span>
  <span class="nt">&#34;offline_enabled&#34;</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> <span class="err">//</span> <span class="err">允许离线运行</span>
  <span class="nt">&#34;permissions&#34;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&#34;activeTab&#34;</span><span class="p">,</span> <span class="s2">&#34;tabs&#34;</span><span class="p">,</span> <span class="s2">&#34;storage&#34;</span><span class="p">],</span> <span class="err">//</span> <span class="err">使用的</span> <span class="err">chrome</span> <span class="err">权限</span>
  <span class="nt">&#34;icons&#34;</span><span class="p">:</span> <span class="p">{</span>
    <span class="err">//</span> <span class="err">图标</span>
    <span class="nt">&#34;16&#34;</span><span class="p">:</span> <span class="s2">&#34;icon-16.png&#34;</span><span class="p">,</span>
    <span class="nt">&#34;32&#34;</span><span class="p">:</span> <span class="s2">&#34;icon-32.png&#34;</span><span class="p">,</span>
    <span class="nt">&#34;48&#34;</span><span class="p">:</span> <span class="s2">&#34;icon-48.png&#34;</span><span class="p">,</span>
    <span class="nt">&#34;64&#34;</span><span class="p">:</span> <span class="s2">&#34;icon-64.png&#34;</span><span class="p">,</span>
    <span class="nt">&#34;128&#34;</span><span class="p">:</span> <span class="s2">&#34;icon-128.png&#34;</span><span class="p">,</span>
    <span class="nt">&#34;200&#34;</span><span class="p">:</span> <span class="s2">&#34;icon-200.png&#34;</span>
  <span class="p">},</span>
  <span class="nt">&#34;content_security_policy&#34;</span><span class="p">:</span> <span class="s2">&#34;script-src &#39;self&#39;; object-src &#39;self&#39;;&#34;</span><span class="p">,</span> <span class="err">//</span> <span class="err">允许加载的文件</span>
  <span class="nt">&#34;background&#34;</span><span class="p">:</span> <span class="p">{</span>
    <span class="nt">&#34;scripts&#34;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&#34;background.js&#34;</span><span class="p">],</span> <span class="err">//</span> <span class="err">外部运行的</span> <span class="err">js</span>
    <span class="nt">&#34;persistent&#34;</span><span class="p">:</span> <span class="kc">false</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-js" data-lang="js"><span class="c1">// background.js
</span><span class="c1">// 点击扩展图标，打开新的 Tag 页面
</span><span class="c1"></span><span class="kd">function</span> <span class="nx">activeNewTab</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">var</span> <span class="nx">chrome</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">chrome</span><span class="p">;</span>
  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">chrome</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span><span class="p">;</span>
  <span class="p">}</span>
  <span class="nx">chrome</span><span class="p">.</span><span class="nx">browserAction</span><span class="p">.</span><span class="nx">onClicked</span><span class="p">.</span><span class="nx">addListener</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="nx">chrome</span><span class="p">.</span><span class="nx">extension</span><span class="p">.</span><span class="nx">getURL</span><span class="p">(</span><span class="s2">&#34;index.html&#34;</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">tabId</span><span class="p">)</span> <span class="p">{</span>
      <span class="nx">chrome</span><span class="p">.</span><span class="nx">tabs</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">tabId</span><span class="p">,</span> <span class="p">{</span> <span class="nx">selected</span><span class="o">:</span> <span class="kc">true</span> <span class="p">});</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
      <span class="nx">chrome</span><span class="p">.</span><span class="nx">tabs</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span> <span class="nx">url</span><span class="o">:</span> <span class="nx">url</span> <span class="p">},</span> <span class="kd">function</span><span class="p">(</span><span class="nx">tab</span><span class="p">)</span> <span class="p">{</span>
        <span class="nb">window</span><span class="p">.</span><span class="nx">tabId</span> <span class="o">=</span> <span class="nx">tab</span><span class="p">.</span><span class="nx">id</span><span class="p">;</span>
      <span class="p">});</span>
    <span class="p">}</span>
  <span class="p">});</span>
  <span class="nx">chrome</span><span class="p">.</span><span class="nx">tabs</span><span class="p">.</span><span class="nx">onRemoved</span><span class="p">.</span><span class="nx">addListener</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">tabId</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="nx">tabId</span> <span class="o">===</span> <span class="nb">window</span><span class="p">.</span><span class="nx">tabId</span><span class="p">)</span> <span class="p">{</span>
      <span class="nb">window</span><span class="p">.</span><span class="nx">tabId</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
    <span class="p">}</span>
  <span class="p">});</span>
<span class="p">}</span>

<span class="nx">activeNewTab</span><span class="p">();</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="上传到-chrome-网上应用商店">上传到 Chrome 网上应用商店</h2>
<p>Chrome 网上应用商店上传地址是 <a href="https://chrome.google.com/webstore/developer/dashboard">https://chrome.google.com/webstore/developer/dashboard</a>。</p>
<p>上传应用需要支付 <strong>5 美元</strong>的开发者费用。对于没有信用卡的人来说，淘宝可以找到相关代付途径，或者寻求朋友帮助。</p>
<p>支付完成就可以上传应用了，一个账号最多上传 <strong>20</strong> 个应用。</p>
<blockquote>
<p>首发 <a href="https://nusr.github.io/">https://nusr.github.io/</a></p>
</blockquote>
  </div>

  <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">早起的年轻人</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2019-07-07 22:28
        
    </span>
  </p>
  
  <p class="copyright-item">
    <span class="item-title">许可协议</span>
    <span class="item-content"><a target="_blank" rel="license noopener" href="https://github.com/nusr/blog/blob/master/LICENSE">MIT</a></span>
  </p>
</div>
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    <label class="qr-code-image" for="reward">
        <img class="image" src="/images/wechat.jpg">
        <span>微信佛系打赏</span>
      </label>
    <label class="qr-code-image" for="reward">
        <img class="image" src="/images/alipay.jpg">
        <span>支付宝佛系打赏</span>
      </label>
  </div>
</div><footer class="post-footer">
    <div class="post-tags">
      <a href="/tags/React/">“React”</a>
      <a href="/tags/Chrome/">Chrome</a>
      </div>
    <nav class="post-nav">
      <a class="prev" href="/post/%E5%BD%93%E4%B8%8B%E7%9A%84%E5%8A%9B%E9%87%8F%E4%B9%A6%E8%AF%84/">
        <i class="iconfont icon-left"></i>
        <span class="prev-text nav-default">《当下的力量》书评</span>
        <span class="prev-text nav-mobile">上一篇</span>
      </a>
      <a class="next" href="/post/2019/2019-05-29-use-rss/">
        <span class="next-text nav-default">使用 RSS 主动阅读技术博客</span>
        <span class="next-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    </nav>
  </footer>
  
</article>
            </div>
            

        </div>
    </main>

    <footer id="footer" class="footer">
        <div class="social-links">
  <a href="852851198@qq.com" class="iconfont icon-email" title="email" rel="noopener" target="_blank" data-title="email"> </a>
  <a href="https://github.com/ITmxs" class="iconfont icon-github" title="github" rel="noopener" target="_blank" data-title="github"> </a>
  <a href="https://juejin.cn/user/3843548384077192" class="iconfont icon-juejin" title="juejin" rel="noopener" target="_blank" data-title="juejin"> </a>
  <a href="https://www.zhihu.com/people/yimi-yang-guang-96-65" class="iconfont icon-zhihu" title="zhihu" rel="noopener" target="_blank" data-title="zhihu"> </a>
  <a href="https://space.bilibili.com/480883651" class="iconfont icon-bilibili" title="bilibili" rel="noopener" target="_blank" data-title="bilibili"> </a>
  <a href="https://luckly.work/index.xml" type="application/rss+xml" rel="noopener" target="_blank" class="iconfont icon-rss" title="rss"></a>


</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 -
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  <div class="busuanzi-footer">
    <span id="busuanzi_container_site_pv"> 本站总访问量 <span id="busuanzi_value_site_pv"><img src="/img/spinner.svg" alt="spinner.svg"/></span> 次 </span>
    <span class="division">|</span>
    <span id="busuanzi_container_site_uv"> 本站总访客数 <span id="busuanzi_value_site_uv"><img src="/img/spinner.svg" alt="spinner.svg"/></span> 人 </span>
  </div>

  <span class="copyright-year">
    &copy;
    2020 -
    2021
    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">早起的年轻人</span>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
    </div>
</div>

  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/timeago.js@3.0.2/dist/timeago.min.js" integrity="sha256-jwCP0NAdCBloaIWTWHmW4i3snUNMHUNO+jr9rYd2iOI=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/timeago.js@3.0.2/dist/timeago.locales.min.js" integrity="sha256-ZwofwC1Lf/faQCzN7nZtfijVV6hSwxjQMwXL4gn9qU8=" crossorigin="anonymous"></script>
  <script><!-- NOTE: timeago.js uses the language code format like "zh_CN" (underscore and case sensitive) -->
    var languageCode = "zh-CN".replace(/-/g, '_').replace(/_(.*)/, function ($0, $1) {return $0.replace($1, $1.toUpperCase());});
    timeago().render(document.querySelectorAll('.timeago'), languageCode);
    timeago.cancel();  
  </script>
<script type="text/javascript" src="/dist/even.47f727f4.min.js"></script>


<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'UA-138883536-1', 'auto');
	ga('set', 'anonymizeIp', true);
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>







</body>
</html>
